/*
 * @Author: your name
 * @Date: 2021-12-20 17:18:43
 * @LastEditTime : 2022-04-22 14:50:25
 * @LastEditors  : Shiming
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath     : \\tms-obc-web\\src\\app\\routes\\sys-setting\\services\\system.service.ts
 */
import { Injectable, Injector } from '@angular/core';
import { BaseService } from 'src/app/shared/services';
import { TreeNodeInterface } from '../../menu-manager/services/menu-manager.service';

@Injectable({
  providedIn: 'root'
})
export class SystemService extends BaseService {
  // 分页查询企业项目员工列表
  $api_get_enterprise_staff_page = '/api/mdc/cuc/userApp/getEnterpriseProjectStaffListPage';
  // 分页查询企业项目员工列表
  $api_export_staff = '/api/mdc/cuc/userApp/enterpriseProjectStaffExport';
  // 添加员工
  $api_add_staff = '/api/mdc/cuc/userApp/addStaff';
  // 编辑员工
  $api_edit_staff = '/api/mdc/cuc/userApp/editorStaff';
  // 删除应用用户(员工)
  $api_delete_staff = '/api/mdc/cuc/userApp/deleteAppUser';
  // 冻结或恢复员工
  $api_free_or_resume_staff = '/api/mdc/cuc/userApp/freezeOrResumeStaff';
  // 获取应用企业的管理员用户
  $api_get_app_admin_info = `/api/mdc/cuc/userApp/getAppEnterpriseAdmin`;
  // 运营管理后台转授超管角色
  $api_set_shift_admin = `/api/mdc/cuc/userAuthority/shiftAdmin`;

  // 分页获取应用角色列表
  $api_get_role_page = '/api/mdc/cuc/roleInfo/getAppRoleInfoList';
  // 分页获取配置角色列表
  $api_get_ent_role_page = '/api/mdc/cuc/roleInfo/getConfigurationRoleList';
  // 新增角色
  $api_save_role = '/api/mdc/cuc/roleInfo/saveRoleInfo';
  // 编辑角色
  $api_update_role = '/api/mdc/cuc/roleInfo/updateRoleInfo';
  // 删除角色(含多个)
  $api_dalete_role = '/api/mdc/cuc/roleInfo/removeRoleInfo';
  // 获取角色详情
  $api_getRoleInfo = '/api/mdc/cuc/roleInfo/getRoleInfo';
  // 获取角色列表
  $api_getAppRoleList = '/api/mdc/cuc/roleInfo/getRoleList';

  // 获取组织角色树列表
  $api_get_organization_role_list = '/api/mdc/cuc/roleInfo/getOrganizationRoleList';

  // 查询字典选项列表
  $api_get_dict_page = '/api/mdc/pbc/dictItems/list/page';
  // 根据id批量删除字典选项
  $api_delete_dict_by_ids = '/api/mdc/pbc/dictItems/deleteBatchByIds';
  // 新增字典选项
  $api_add_dict = '/api/mdc/pbc/dictItems/save';
  // 更新字典选项
  $api_update_dict = '/api/mdc/pbc/dictItems/update';

  // 获取CRM客户信息表
  $api_get_crmCustomer = '/api/mdc/cuc/crmCustomer/get';
  // 查询CRM客户信息表
  $api_get_crmCustomer_page = '/api/mdc/cuc/crmCustomer/list/page';
  // 保存CRM客户信息表
  $api_save_crmCustomer = '/api/mdc/cuc/crmCustomer/save';
  // 删除CRM客户信息表
  $api_deletebatch_crmCustomer = '/api/mdc/cuc/crmCustomer/deletebatch';

  // 获取某个应用的所有菜单
  $api_getAllFunctionInfoByAppId: string = '/api/mdc/cuc/functionInfo/getAllFunctionInfoByAppId';

  // 查询网络货运信息表
  $api_networkTransporter_page = '/api/mdc/cuc/networkTransporter/list/page';
  // 获取网络货运信息表(id)
  $api_get_networkTransporter = '/api/mdc/cuc/networkTransporter/get';
  // 获取网络货运信息表(id)
  $api_get_networkTransporter_getDetail = '/api/mdc/cuc/networkTransporter/getDetail';
  // 批量获取网络货运信息
  $api_findNetworkTransporterByIds = '/api/mdc/cuc/networkTransporter/findNetworkTransporterByIds';
  // 查找所有网络货运信息(下拉)
  $api_networkTransporter_findAll = '/api/mdc/cuc/networkTransporter/findAll';
  // 删除网络货运信息表
  $api_networkTransporter_deletebatch = '/api/mdc/cuc/networkTransporter/deletebatch';
  // 保存网络货运信息表
  $api_networkTransporter_save = '/api/mdc/cuc/networkTransporter/save';

  // 查询结算客户表
  $api_settlementCustomer_page = '/api/mdc/cuc/settlementCustomer/list/page';
  // 获取结算客户表
  $api_settlementCustomer_get = '/api/mdc/cuc/settlementCustomer/get';
  // 保存结算客户表
  $api_settlementCustomer_save = '/api/mdc/cuc/settlementCustomer/save';
  // 删除结算客户表
  $api_settlementCustomer_deletebatch = '/api/mdc/cuc/settlementCustomer/deletebatch';
  // 获取货主企业列表
  public $api_enterpriceList = '/api/mdc/cuc/enterpriseInfo/operate/enterpriceList';

  // 查询协议列表
  public $api_get_agreement_page = '/api/mdc/pbc/agreementInfo/list/page';
  // 编辑协议
  public $api_update_agreement = '/api/mdc/pbc/agreementInfo/modifyAgreementInfo';

  // 根据FullKey获取系统子配置(树)
  public $api_get_config_tree = '/api/mdc/pbc/sysConfig/getSysConfigTreeByParentFullKey';
  // 查找系统配置项列表
  public $api_get_config_by_parent_id = '/api/mdc/pbc/sysConfigItem/findSysConfigItemBySysConfigId';
  // 新增系统配置
  public $api_add_config = '/api/mdc/pbc/sysConfig/save';
  // 更新系统配置
  public $api_update_config = '/api/mdc/pbc/sysConfig/update';
  // 更新系统配置排序
  public $api_update_config_sort = '/api/mdc/pbc/sysConfig/updateSort';
  // 删除系统配置
  public $api_remove_config = '/api/mdc/pbc/sysConfig/deletebatch';
  // 查询系统配置项
  public $api_get_config_item_page = '/api/mdc/pbc/sysConfigItem/list/page';
  // 新增系统配置项
  public $api_add_config_item = '/api/mdc/pbc/sysConfigItem/save';
  // 更新系统配置项
  public $api_update_config_item = '/api/mdc/pbc/sysConfigItem/update';
  // 批量更新系统配置项
  public $api_update_config_batch = '/api/mdc/pbc/sysConfigItem/updateBatch';
  // 更新系统配置项排序
  public $api_update_config_item_sort = '/api/mdc/pbc/sysConfigItem/updateSort';
  // 删除系统配置项
  public $api_remove_config_item = '/api/mdc/pbc/sysConfigItem/deletebatch';

  // 根据网络货运人ID获取票务信息
  public $api_getTicketByNetworkTransporterId = '/api/mdc/cuc/networkTransporterTicket/getTicketByNetworkTransporterId';
  // 保存票务信息
  public $api_networkTransporterTicket_save = '/api/mdc/cuc/networkTransporterTicket/save';
  // 根据地区code查询列表
  $api_get_region_by_code = '/api/mdc/pbc/region/getRegionByCode';
  // 根据地区code查询地区详情
  $api_getRegionDetailByCode = '/api/mdc/pbc/region/getRegionDetailByCode';

  // 分页查询按钮列表
  $api_getButtonInfoPage = '/api/mdc/cuc/buttonInfo/getButtonInfoPage';
  // 新增编辑按钮信息
  $api_saveButtonInfo = '/api/mdc/cuc/buttonInfo/saveButtonInfo';
  // 获取按钮信息表(id)
  $api_getButtonInfo_one = '/api/mdc/cuc/buttonInfo/getButtonInfo';
  // 删除按钮信息(id)
  $api_deletebatchButton = '/api/mdc/cuc/buttonInfo/deletebatchButton';

  // 根据条件获取公告列表
  $api_getAnnouncementInfoList_page = '/api/mdc/pbc/announcementInfo/getAnnouncementInfoList';
  // 获取公告信息详情
  $api_getAnnouncementInfoById_detail = '/api/mdc/pbc/announcementInfo/getAnnouncementInfoById';
  // 删除公告信息
  $api_delete_deleteAnnouncementInfoById = '/api/mdc/pbc/announcementInfo/deleteAnnouncementInfoById';
  // 编辑公告信息
  $api_modifyAnnouncementInfo = '/api/mdc/pbc/announcementInfo/modifyAnnouncementInfo';
  // 新增公告信息
  $api_addAnnouncementInfo = '/api/mdc/pbc/announcementInfo/addAnnouncementInfo';

  // 查询保险配置
  $api_insuranceConfig_list = '/api/mdc/cuc/insuranceConfig/list';
  // 获取保险配置费率
  $api_getInsuranceRate = '/api/mdc/cuc/insuranceConfig/getInsuranceRate';
  // 获取保险配置(id)
  $api_getInsuranceRate_get = '/api/mdc/cuc/insuranceConfig/get';
  // 删除保险配置(id)
  $api_getInsuranceRate_deletebatch = '/api/mdc/cuc/insuranceConfig/deletebatch';
  // 批量保存保险配置
  $api_getInsuranceRate_saveBatch = '/api/mdc/cuc/insuranceConfig/saveBatch';

  // 营业执照识别
  $api_ocr_recognize_business_license = '/api/mdc/pbc/hwc/ocr/recognizeBusinessLicense';
  // 短信发送列表
  $api_listSmsSendLog = '/api/mdc/pbc/smsSend/listSmsSendLog';
  // 身份证识别
  $api_ocr_recognize_id_card = '/api/mdc/pbc/hwc/ocr/recognizeIdCard';
  // 获取字典
  $api_getDictValue = '/api/mdc/pbc/dictItems/getDictValue';
  // 设置crm客户
  $api_setCrmCustomer = '/api/mdc/cuc/networkTransporter/setCrmCustomer';
  // 获取一、二、三级地区详情
  $api_getRegionToThree = '/api/mdc/pbc/region/getRegionToThree';
  // 道路运输证识别
  $api_recognizeTransportationLicense = '/api/mdc/pbc/hwc/ocr/recognizeTransportationLicense';
  $api_getRoleTemplateInfo: string = '';
  $api_getFunctionButtonInfo: string = '/api/mdc/cuc/functionButton/getFunctionButtonByFunctionId';
  $api_getFunctionDataInfo: string = '';
  $api_getAppList: string = '';
  $api_getRoleTemplateListByAppId: string = '';
  $api_updateRoleInfo: string = '';

  // 短信模板list
  $api_smsTemplate_page = '/api/mdc/pbc/smsTemplate/list/page';
  // 短信模板编辑
  $api_smsTemplate_edit = '/api/mdc/pbc/smsTemplate/save';

  constructor(public injector: Injector) {
    super(injector);
  }

  collapse(array: TreeNodeInterface[], data: TreeNodeInterface, $event: boolean): void {
    if (!$event) {
      if (data.children) {
        data.children.forEach(d => {
          const target = array.find(a => a.key === d.key)!;
          target.expand = false;
          this.collapse(array, target, false);
        });
      } else {
        return;
      }
    }
  }

  convertTreeToList(root: TreeNodeInterface): TreeNodeInterface[] {
    const stack: TreeNodeInterface[] = [];
    const array: TreeNodeInterface[] = [];
    const hashMap = {};
    stack.push({ ...root, level: 0, expand: true });

    while (stack.length !== 0) {
      const node = stack.pop()!;
      this.visitNode(node, hashMap, array);
      if (node.children) {
        for (let i = node.children.length - 1; i >= 0; i--) {
          stack.push({
            ...node.children[i],
            level: node.level! + 1,
            expand: false,
            parent: node
          });
        }
      }
    }

    return array;
  }

  visitNode(node: TreeNodeInterface, hashMap: { [key: string]: boolean }, array: TreeNodeInterface[]): void {
    if (!hashMap[node.key]) {
      hashMap[node.key] = true;
      array.push(node);
    }
  }
}
